Public Class UserList
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents dgUserList As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected WithEvents Header1 As Header

#Region " Properties"
    Private Property Url() As String
        Get
            Return CStr(ViewState("Url"))
        End Get
        Set(ByVal Value As String)
            ViewState("Url") = Value
        End Set
    End Property

    Private Property UrlReferrer() As String
        Get
            Return CStr(ViewState("UrlReferrer"))
        End Get
        Set(ByVal Value As String)
            ViewState("UrlReferrer") = Value
        End Set
    End Property
#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initilize the page here
        If Not Me.IsPostBack Then
            Me.Url = Request.Url.PathAndQuery
            Me.UrlReferrer = Request.UrlReferrer.PathAndQuery

            'Assign header
            Header1.NavigationBar.Add("Create new user", "User.aspx")
            Header1.NavigationBar.Add("Refresh", Me.Url)
            Header1.NavigationBar.Add("Back", Me.UrlReferrer)

            Header1.MenuIndex = EMenuIndex.InternalUserList

            Me.BindGrid()
        End If
    End Sub

    Private Sub BindGrid()
        If Not Me.IsPostBack Then
            'Build datagrid
            Dim dt As DataTable = CUser.GetUserList()
            Session("UserList") = dt
            Me.dgUserList.DataSource = dt
            Me.dgUserList.DataBind()
        End If
    End Sub

    Private Sub dgUserList_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgUserList.SortCommand
        ' Retrieve the data source from session state.
        Dim dt As DataTable = CType(Session("UserList"), DataTable)

        ' Create a DataView from the DataTable.
        Dim dv As DataView = New DataView(dt)

        ' The DataView provides an easy way to sort. Simply set the
        ' Sort property with the name of the field to sort by.
        dv.Sort = e.SortExpression

        ' Rebind the data source and specify that it should be sorted
        ' by the field specified in the SortExpression property.
        dgUserList.DataSource = dv
        dgUserList.DataBind()
    End Sub
End Class
